#include <bits/stdc++.h>
using namespace std;
struct node
{
    bool flag;
    int o;
}x[111111];
struct p
{
    int l,r;
}ans[111111];
int t;
int n,m,l,tp;
int pos[111111];
int hzh[111111];
vector<pair<int,int>>g;
vector<pair<int,int>>rl;
int d[111111],v[111111],a[111111];
bool cmp(pair<int,int>a,pair<int,int>b)
{
    if (a.first!=b.first)
    {
        return a.first<b.first;
    }
    else
    {
        return a.second>b.second;
    }
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while (t--)
    {
        cin>>n>>m>>l>>tp;
        for (int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&d[i],&v[i],&a[i]);
            if (a[i]==0)
            {
                if (v[i]>tp)
                {
                    ans[i].l=d[i];
                    ans[i].r=l;
                }
                else
                {
                    ans[i].l=-1;
                    ans[i].r=-1;
                }
            }
            else if (a[i]>0)
            {
                x[i].flag=0;
                x[i].o=floor((tp*tp-v[i]*v[i])/(2*a[i]))+1;
            }
            else
            {
                x[i].flag=1;
                x[i].o=floor((tp*tp-v[i]*v[i])/(2*a[i]));
                if ((tp*tp-v[i]*v[i])%(2*a[i])==0)
                {
                    x[i].o--;
                }
            }
        }
        for (int i=1;i<=n;i++)
        {
            if (a[i]!=0)
            {
                int ll,rr;
                if (!x[i].flag)
                {
                    ll=d[i]+x[i].o;
                    rr=l;
                }
                else
                {
                    ll=d[i];
                    rr=d[i]+x[i].o;
                }
                ll=max(ll,d[i]);
                rr=min(rr,l);
                if (ll<=rr)
                {
                    ans[i].l=ll;
                    ans[i].r=rr;
                }
                else
                {
                    ans[i].l=-1;
                    ans[i].r=-1;
                }
            }
        }
        for (int i=1;i<=m;i++)
        {
            scanf("%d",&pos[i]);
        }
        sort(pos+1,pos+m+1);
        int cnt=0,tot=0;
        bool flag1=0,flag2=0;
        g.clear();
        int ih=-1;
        for (int i=1;i<=n;i++)
        {
            if (ans[i].l!=-1&&ans[i].r!=-1&&ans[i].l<=ans[i].r)
            {
                int x=lower_bound(pos+1,pos+m+1,ans[i].l)-pos;
                int y=upper_bound(pos+1,pos+m+1,ans[i].r)-pos-1;
                if (x<=y)
                {
                    cnt++;
                    if (a[i]>=0)
                    {
                        flag1=1;
                        ih=max(ih,x);
                    }
                    else
                    {
                        flag2=1;
                        g.push_back({x,y});
                    }
                }
            }
        }
        tot+=flag1;
        sort(g.begin(),g.end(),cmp);
        rl.clear();
        for (int i=0;i<g.size();i++)
        {
            hzh[i]=0;
        }
        hzh[g.size()]=1e9;
        for (int i=g.size()-1;i>=1;i--)
        {
            hzh[i]=min(hzh[i+1],g[i].second);
        }
        for (int i=0;i<g.size();i++)
        {
            if (g[i].second<hzh[i+1])
            {
                rl.push_back(g[i]);
            }
        }
        int now=-1;
        for (auto i:rl)
        {
            if (now<i.first)
            {
                tot++;
                now=i.second;
            }
        }
        if (ih!=-1&&ih<=now)
        {
            tot--;
        }
        cout<<cnt<<" "<<m-tot<<endl;//<<" "<<m-tot<<endl;
    }
    return 0;
}
